package com.darkteam.jhades.cs.message;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;

import com.darkteam.jhades.common.message.JHadesSerializable;

public class ServerAddress implements JHadesSerializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2308555755440762587L;
	
	
	private String address;
	
	private short port;
	
	
	

	public ServerAddress(String address, short port) {
		super();
		this.address = address;
		this.port = port;
	}



	public String getAddress() {
		return address;
	}



	public void setAddress(String address) {
		this.address = address;
	}



	public short getPort() {
		return port;
	}



	public void setPort(short port) {
		this.port = port;
	}



	@Override
	public ChannelBuffer toChannelBuffer() {
		ChannelBuffer buffer = ChannelBuffers.buffer(20);
		byte[] addressByte = address.getBytes();
		buffer.writeBytes(addressByte);
		if(addressByte.length < 16){
			buffer.writeZero(16 - addressByte.length);
		}	
		buffer.writeShort(Short.reverseBytes(port));
		
		
		return buffer;
	}

}
